﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Lvzhi.Core;
using Lvzhi.Provide.Rpg;

namespace Lvzhi.Website.Controllers
{
    /// <summary>
    /// 首页
    /// </summary>
    public class MainController : Controller
    {
        private GoodsCore gCore = new GoodsCore();
        /// <summary>
        /// 首页
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            //首页所有的置顶/推荐的植物
            var plants = gCore.LoadEntities(o => o.G_Top == 1 || o.G_Recom == 1).ToList();


            ViewBag.AdIndexBanner = ConfigurationManager.AppSettings["adIndexBanner"];

            return View(plants);
        }
        /// <summary>
        /// 分类搜索
        /// </summary>
        /// <returns></returns>
        public ActionResult Category(int id = 0)
        {
            CategoryCore cCore = new CategoryCore();

            var category = cCore.LoadEntities(o => o.C_State == 0).OrderBy(o => o.C_Rank).ToList();

            if (id > 0)
            {
                //没有子分类 直接跳转
                if (category.Count(o => o.C_PId == id) < 1)
                {
                    return Redirect("/plants/index/" + id);
                }
            }
            ViewBag.cid = id;
            return View(category);
        }

        /// <summary>
        /// 分部页，高级搜索
        /// </summary>
        /// <returns></returns>
        [ChildActionOnly]
        public PartialViewResult PlantsFilter()
        {
            string history = CookieHelper.GetCookieValue("idol_history");
            return PartialView(model:history);
        }
    }
}